﻿using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Routing;
using System;

namespace WebAdmin.Handler
{
    /// <summary>
    /// 仅允许Ajax操作
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class AjaxOnlyAttribute : ActionMethodSelectorAttribute
    {
        /// <summary>
        /// 验证请求有效性
        /// </summary>
        public override bool IsValidForRequest(RouteContext controllerContext, ActionDescriptor action)
        {
            return BizPage.IsAjaxRequest(controllerContext.HttpContext.Request);
        }
    }
}
